//
//  LGCustomerServiceController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/27.
//  帮助与客服

#import "LGCustomerServiceController.h"

@interface LGCustomerServiceController ()

/**   */
@property (nonatomic , strong)UIImageView *bgImageView;
/**   */
@property (nonatomic , strong)UILabel *phoneLabel;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UIButton *phoneBtn;
/**   */
@property (nonatomic , copy)NSString *phoneNumber;

@end

@implementation LGCustomerServiceController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"客服与帮助";
    self.view.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    [self.view addSubview:self.bgImageView];
    [self.view addSubview:self.phoneLabel];
    [self.view addSubview:self.timeLabel];
    [self.view addSubview:self.phoneBtn];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/common/dict/kefu" parameters:@{} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            self.phoneNumber = LGNSString(returnData[@"phone"]);
            self.phoneLabel.text = [NSString stringWithFormat:@"客服电话：%@",returnData[@"phone"]];
            self.timeLabel.text = [NSString stringWithFormat:@"服务时间：%@~%@",returnData[@"service_open_time"],returnData[@"service_close_time"]];
        }
    } error:^(NSError *error) {
        
    }];
}

-(void)makePhoneCall{
    if(_phoneNumber && _phoneNumber.length>0){
        NSString *phone = [NSString stringWithFormat:@"telprompt://%@",self.phoneNumber];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phone] options:@{} completionHandler:nil];
    }else{
        [self requestData];
    }
}

-(UIImageView *)bgImageView{
    if(!_bgImageView){
        _bgImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"帮助与客服"]];
        _bgImageView.frame = CGRectMake(0, 0, Screen_W, viewPix(240));
    }
    return _bgImageView;
}

-(UILabel *)phoneLabel{
    if(!_phoneLabel){
        _phoneLabel = [UILabel lableWithText:@"客服电话：" colorString:@"#333333" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _phoneLabel.frame = CGRectMake(viewPix(20), kMaxY(self.bgImageView.frame)+viewPix(43), Screen_W-viewPix(40), viewPix(25));
    }
    return _phoneLabel;
}


-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"服务时间：" colorString:@"#999999" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _timeLabel.frame = CGRectMake(viewPix(20), kMaxY(self.phoneLabel.frame)+viewPix(12), Screen_W-viewPix(40), viewPix(21));
    }
    return _timeLabel;
}

-(UIButton *)phoneBtn{
    if(!_phoneBtn){
        _phoneBtn = [UIButton buttonWithTitle:@"拨打" topMargin:kMaxY(self.timeLabel.frame)+viewPix(135)];
        [_phoneBtn addTarget:self action:@selector(makePhoneCall) forControlEvents:UIControlEventTouchUpInside];
    }
    return _phoneBtn;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
